from threading import Thread
import asyncio


async def task1():
    print("子线程的携程1::开始")
    await asyncio.sleep(2)
    print("子线程的携程1::结束")


async def task2():
    print("子线程的携程2::开始")
    await asyncio.sleep(2)
    print("子线程的携程2::结束")


async def main_task1():
    print("主线程的携程1::开始")
    await asyncio.sleep(2)
    print("主线程的携程1::结束")


async def main_task2():
    print("主线程的携程2::开始")
    await asyncio.sleep(2)
    print("主线程的携程2::结束")


async def main():
    tasks = [task1(), task2()]
    res = await asyncio.gather(*tasks)
    return res


def sub_thread():
    print("子线程开始!")
    loop = asyncio.new_event_loop()
    loop.run_until_complete(main())
    print("子线程结束!")


async def main_main():
    task = [main_task1(), main_task2()]
    res = await asyncio.gather(*task)
    return res


if __name__ == '__main__':
    print("主线程开始")
    proc = Thread(target=sub_thread)
    proc.start()
    loop = asyncio.new_event_loop()
    loop.run_until_complete(main_main())
    proc.join()
    print("主线程结束!")
